// components/GBTRankingList/GBTRankingList.js
Component({

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function() {
      this.setData({
        isTodaySelected: false,
        isThismonthSelected: true,
        isThisyearSelected: false,
      });
      let date = new Date();
      let firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
      let lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
      let data = {};
      data.startTime = firstDay.getFullYear() + "-" + (firstDay.getMonth() + 1) + "-" + firstDay.getDate() + " 00:00:00";
      data.endTime = lastDay.getFullYear() + "-" + (lastDay.getMonth() + 1) + "-" + lastDay.getDate() + " 23:59:59";
      this.setData({
        data: data,
      });
    },
    hide: function() {

    },
    resize: function() {},
  },
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: "销售排行（业务员）",
    },
    disableMenu: {
      type: Boolean,
      value: false,
    },
    one: {
      type: String,
      value: "今日",
    },
    two: {
      type: String,
      value: "今月",
    },
    three: {
      type: String,
      value: "今年",
    },
    rankingList: {
      type: JSON,
      value: [],
    },
    data: {
      type: JSON,
      value: {},
    },
    isRanking: {
      type: Boolean,
      value: false,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    title: "",
    disableMenu: false,
    one: "今日",
    two: "今月",
    three: "今年",
    isTodaySelected: false,
    isThismonthSelected: true,
    isThisyearSelected: false,
    rankingList: [],
    rankingNumImg: "",
    data: {},
    isRanking: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onToday: function() {
      let selected = this.data.isTodaySelected;
      if (!selected) {
        this.setData({
          isTodaySelected: true,
          isThismonthSelected: false,
          isThisyearSelected: false,
        });

        let date = new Date();
        date.setTime(date.getTime());
        let data = {};
        data.startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 00:00:00";
        data.endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " 23:59:59";
        this.setData({
          data: data,
        });
        this.triggerEvent("one", {
          data
        }, {});
      }
    },
    onThismonth: function() {
      let selected = this.data.isThismonthSelected;
      if (!selected) {
        this.setData({
          isTodaySelected: false,
          isThismonthSelected: true,
          isThisyearSelected: false,
        });

        let date = new Date();
        let firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
        let lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
        let data = {};
        data.startTime = firstDay.getFullYear() + "-" + (firstDay.getMonth() + 1) + "-" + firstDay.getDate() + " 00:00:00";
        data.endTime = lastDay.getFullYear() + "-" + (lastDay.getMonth() + 1) + "-" + lastDay.getDate() + " 23:59:59";
        this.setData({
          data: data,
        });
        this.triggerEvent("two", {
          data
        }, {});
      }
    },
    onThisyear: function() {
      let selected = this.data.isThisyearSelected;
      if (!selected) {
        this.setData({
          isTodaySelected: false,
          isThismonthSelected: false,
          isThisyearSelected: true,
        });

        let date = new Date();
        let firstDay = new Date(date.getFullYear(), 0, 1);
        let lastDay = new Date(date.getFullYear(), 12, 0);
        let data = {};
        data.startTime = firstDay.getFullYear() + "-" + (firstDay.getMonth() + 1) + "-" + firstDay.getDate() + " 00:00:00";
        data.endTime = lastDay.getFullYear() + "-" + (lastDay.getMonth() + 1) + "-" + lastDay.getDate() + " 23:59:59";
        this.setData({
          data: data,
        });
        this.triggerEvent("three", {
          data
        }, {});
      }
    },
    onSeeAll: function() {
      this.triggerEvent("seeall", {}, {});
    }
  }
})